package com.lineage.data.item_etcitem.wand;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.NpcSpawnTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;

public class Npc_RemoveNpc_Wand extends ItemExecutor {
  public static ItemExecutor get() {
    return new Npc_RemoveNpc_Wand();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targetID = data[0];
    L1Object target = World.get().findObject(targetID);
    if (target != null && target instanceof L1NpcInstance) {
      pc.sendPacketsX8((ServerBasePacket)new S_DoActionGFX(pc.getId(), 17));
      L1NpcInstance npc = (L1NpcInstance)target;
      NpcSpawnTable.get();
      NpcSpawnTable.delete(npc.getNpcId());
      npc.setreSpawn(false);
      npc.deleteMe();
      pc.sendPackets((ServerBasePacket)new S_SystemMessage(String.valueOf(npc.getNpcId()) + npc.getName() + "2秒钟后删除."));
      pc.getInventory().updateItem(item, 128);
    } 
  }
}
